package com.ruoyi.common.utils.file.upload;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;

import com.ruoyi.project.system.domain.SysFile;
import com.ruoyi.framework.config.FTPConfig;
import com.ruoyi.framework.config.RuoYiConfig;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
@Qualifier("CommonUpload")
public class CommonUpload extends FileUploadTemplate {
    @Override
    public void setFilePath(SysFile fileInfo) {
        fileInfo.setFilePath(RuoYiConfig.getUploadPath()+ Constants.URLPath_SPLIT+ DateUtils.datePath());
    }

    @Override
    public void setIsFTP(SysFile fileInfo) {
        fileInfo.setIsftp(true);
    }

    @Override
    public void setFTPPath(SysFile fileInfo) {
        fileInfo.setFileFtppath(FTPConfig.getPrefix()+Constants.URLPath_SPLIT+"pictual");
    }

    @Override
    public void setFileName(MultipartFile file, SysFile fileInfo) {
        String fileName = file.getOriginalFilename();
        fileInfo.setOriginFilename(fileName);
        String extension = FileUploadUtils.getExtension(file);
        fileName ="中文" + "." + extension;
        fileInfo.setFileName(fileName);
    }

    @Override
    public void setAllowedExtension(SysFile fileInfo) {
        fileInfo.setAllowedExtension(new String[]{"*"});
    }
}
